package com.junzerg.tooltip.controller.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import okhttp3.HttpUrl;

import java.util.HashMap;
import java.util.Map;

/**
 * @author pengjz <br>
 * @version 1.0 <br>
 * @description AmapPoiRequest <br>
 * @date 2022/4/10 16:40 <br>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AmapPoiRequest {

    private String key;
    private String location;
    private String keywords;
    private String types;
    private String city;
    private String citylimit;
    private String children;
    private Integer offset;
    private Integer page;
    private String extensions;
    private String output;
    private String callback;
    private String radius;
    private String sortrule;
    private String polygon;

    public HttpUrl urlBuilder(String url) {
        HttpUrl.Builder builder = HttpUrl.parse(url).newBuilder();
        assert this.key != null;
        builder.addQueryParameter("key", this.key);
        if (this.location != null) {
            builder.addQueryParameter("location", this.location);
        }
        if (this.keywords != null) {
            builder.addQueryParameter("keywords", this.keywords);
        }
        if (this.types != null) {
            builder.addQueryParameter("types", this.types);
        }
        if (this.city != null) {
            builder.addQueryParameter("city", this.city);
        }
        if (this.citylimit != null) {
            builder.addQueryParameter("citylimit", this.citylimit);
        }
        if (this.children != null) {
            builder.addQueryParameter("children", this.children);
        }
        if (this.offset != null) {
            builder.addQueryParameter("offset", String.valueOf(this.offset));
        }
        if (this.page != null) {
            builder.addQueryParameter("page", String.valueOf(this.page));
        }
        if (this.extensions != null) {
            builder.addQueryParameter("extensions", this.extensions);
        }
        if (this.output != null) {
            builder.addQueryParameter("output", this.output);
        }
        if (this.callback != null) {
            builder.addQueryParameter("callback", this.callback);
        }
        if (this.radius != null) {
            builder.addQueryParameter("radius", this.radius);
        }
        if (this.sortrule != null) {
            builder.addQueryParameter("sortrule", this.sortrule);
        }
        if (this.polygon != null) {
            builder.addQueryParameter("polygon", this.polygon);
        }
        return builder.build();
    }

    public Map<String, Object> buildParamMap() {
        Map<String,Object> builder = new HashMap<>();
        assert this.key != null;
        builder.put("key", this.key);
        if (this.location != null) {
            builder.put("location", this.location);
        }
        if (this.keywords != null) {
            builder.put("keywords", this.keywords);
        }
        if (this.types != null) {
            builder.put("types", this.types);
        }
        if (this.city != null) {
            builder.put("city", this.city);
        }
        if (this.citylimit != null) {
            builder.put("citylimit", this.citylimit);
        }
        if (this.children != null) {
            builder.put("children", this.children);
        }
        if (this.offset != null) {
            builder.put("offset", String.valueOf(this.offset));
        }
        if (this.page != null) {
            builder.put("page", String.valueOf(this.page));
        }
        if (this.extensions != null) {
            builder.put("extensions", this.extensions);
        }
        if (this.output != null) {
            builder.put("output", this.output);
        }
        if (this.callback != null) {
            builder.put("callback", this.callback);
        }
        if (this.radius != null) {
            builder.put("radius", this.radius);
        }
        if (this.sortrule != null) {
            builder.put("sortrule", this.sortrule);
        }
        if (this.polygon != null) {
            builder.put("polygon", this.polygon);
        }
        return builder;
    }
}
